package org.example.lotterysystem.common.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.example.lotterysystem.common.errorcode.ErrorCode;

import java.util.Objects;

@Data
@EqualsAndHashCode(callSuper = true)
public class ControllerException extends RuntimeException{
    /**
     异常码
     * @see package org.example.lotterysystem.common.errorcode.ControllerErrorCodeConstants
     */
    private Integer code;
    //异常信息
    private String message;

    //为了序列化
    public ControllerException() {

    }

    @Override
    public String toString() {
        return "ControllerException{" +
                "code=" + code +
                ", message='" + message + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ControllerException that = (ControllerException) o;
        return Objects.equals(code, that.code) && Objects.equals(message, that.message);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, message);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public ControllerException(Integer code, String msg) {
        this.code = code;
        this.message = msg;
    }

    public ControllerException(ErrorCode code) {
      this.code = code.getCode();
      this.message = code.getMsg();
    }
}
